<?php

$logDir = '/var/lib/stickshift/47656e863347468ca33623f6510a6b98/Bin/logs/site_stat_log';

date_default_timezone_set('PRC');

//127.0.0.1 - - [12/Apr/2011:10:25:39 +0800] "GET /phpmyadmin/print.css HTTP/1.1" 200 1063 "http://localhost/phpmyadmin/" "Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0"

include dirname(__FILE__).'/Source/commonFunc.inc.php';

$code = '503';

$logFormat = '{ip} {ident} {author} [{date}] "{methodType} {requestUri} {protocol}" {status} {bytes} "{referer}" "{user-agent}"';

$logData = array();
$logData['{ip}'] = get_client_ip();
$logData['{ident}'] = '-';
$logData['{author}'] = '-';
$logData['{date}'] = date('d/M/Y:H:i:s P');
$logData['{methodType}'] = $_SERVER['REQUEST_METHOD'];
$logData['{requestUri}'] = $_SERVER['REQUEST_URI'];
$logData['{protocol}'] = $_SERVER['SERVER_PROTOCOL'];
$logData['{status}'] = $code;
$logData['{bytes}'] = '0';
$logData['{referer}'] = $_SERVER['HTTP_REFERER'];
$logData['{user-agent}'] = $_SERVER['HTTP_USER_AGENT'];


//exp Log
$logFormat .= ' "{cookie}"';
$logData['{cookie}'] = '';
foreach($_COOKIE as $key=>$val)
{
	$logData['{cookie}'] .= rawurlencode($key).'='.rawurlencode($val).'; ';
}
$logData['{cookie}'] = rtrim($logData['{cookie}'], '; ');

$logStr = str_replace(array_keys($logData), $logData, $logFormat);

$logFile = 'site-stat-'.date('ymdH').'.log';
file_put_contents($logDir.'/'.$logFile, $logStr."\n", FILE_APPEND);

header('HTTP/1.0 '.$code.' Forbidden');
